var app = require('express');
var router = app.Router();

const ROOT_PATH = require('app-root-path'),//项目根路径
  db = require(ROOT_PATH + "/db"),//项目根路径
  common = require(ROOT_PATH + "/common/common");

router.get('/userlist',function(req, res, next){
  var reqData = common.is_key(req.query, req.body);
    let page = reqData.page * 1 || 1;
    let limit = reqData.limit * 1 || 10;
    let sql = "select * from person order by id desc limit ?,?;";
    db.queryAll(sql, (page - 1) * limit, limit)
      .then((data) => {
        if(data.length > 0){
          res.json({
            data,
            status: 200,
            msg: "访问成功"
          });
        }else{
          res.json({
            data,
            status: 201,
            msg: "没有数据"
          });
        }
      });
});

module.exports = router;

/*module.exports = {
  login(req, res, next) {
    var reqData = common.is_key(req.query, req.body);
    console.log(reqData);
    let page = resData.page * 1 || 1;
    let limit = resData.limit * 1 || 10;
    let sql = "select * from person order by id desc limit ?,?;";
    db.queryAll(sql, (page - 1) * limit, limit)
      .then((data) => {
        res.json({
          data
        });
      });
  }
}*/